package com.example.Siki.Config;

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;


public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        //接收参数
        String language = httpServletRequest.getParameter("lang");
        Locale aDefault = Locale.getDefault();//如果没有就使用默认的

        //如果请求连接携带了参数
        if(!StringUtils.isEmpty(language)){
            //分割
            //zh_CN
            String[] lang = language.split("_");
            //国家，地区
            new Locale(lang[0],lang[1]);
        }
        return aDefault;

    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
